﻿using Docker.DotNet;
using Docker.DotNet.BasicAuth;
using Docker.DotNet.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace CodeCity.K8S
{
    public class DockerHelper
    {
        private readonly string deamonUrl;
        private BasicAuthCredentials credentials = new BasicAuthCredentials("1101385391@qq.com", "codecity123");
        public DockerHelper(string username, string password, string deamonUrl)
        {
            credentials = new BasicAuthCredentials(username, password);
            this.deamonUrl = deamonUrl;
        }

        public async System.Threading.Tasks.Task<IList<ImagesListResponse>> ListImageAsync(string registry)
        {
            var client = new DockerClientConfiguration(
               new Uri(deamonUrl),
               credentials)
              .CreateClient();
            var images = await client.Images.ListImagesAsync(new Docker.DotNet.Models.ImagesListParameters()
            {
                All = true
            });
            return images;
        }
    }
}
